home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / GEDEV100.ZIP;1 / C.ZIP / PASCAL.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-10-12  |  1.8 KB  |  95 lines

  1. ;
  2. ; Pascal <--> C string conversion
  3. ;
  4. ; Written by Gerard J. van der Land
  5. ;
  6. ; Copyright (C) 1992 Gerard J. van der Land. All rights reserved.
  7. ;
  8. ; Last updates: 12-Oct-92
  9. ;
  10. ; prototypes:
  11. ;
  12. ; void pascal c2p(char far *dest, const char far *src, byte max);
  13. ; void pascal p2c(char far *dest, const char far *src, byte max);
  14. ;
  15.  
  16. .MODEL COMPACT
  17.  
  18. .CODE
  19.  
  20. public C2P
  21. public P2C
  22.  
  23. C2P proc near
  24.    push    bp
  25.    mov     bp, sp
  26.    push    si
  27.    mov     bx, di
  28.    mov     dx, ds
  29.    les     di, [bp+6]   ; ES:DI = src
  30.    xor     ax, ax
  31.    mov     cx, 0FFFFh
  32.    repnz   scasb
  33.    not     cx
  34.    dec     cx           ; CX = strlen(src)
  35.    mov     al, [bp+4]   ; AX = max (AH is still zero)
  36.    cmp     cx, ax
  37.    jb      c2p_copy
  38.    mov     cx, ax       ; if (CX >= max) CX = max
  39. c2p_copy:
  40.    lds    si, [bp+6]    ; DS:SI = src
  41.    les    di, [bp+10]   ; ES:DI = dest
  42.    mov    al, cl
  43.    stosb
  44.    shr    cx, 1
  45.    rep    movsw
  46.    adc    cx, cx
  47.    rep    movsb
  48.    mov    ds, dx
  49.    mov    di, bx
  50.    pop    si
  51.    pop    bp
  52.    ret    10
  53. C2P endp
  54.  
  55. P2C proc near
  56.    push    bp
  57.    mov     bp, sp
  58.    push    si
  59.    push    di
  60.    push    ds
  61.    lds     si, [bp+6]   ; DS:SI = src
  62.    lodsb
  63.    xor     ch, ch
  64.    mov     cl, al       ; CX = Length(src)
  65.    mov     bh, ch
  66.    mov     bl, [bp+4]   ; BX = max
  67.    cmp     cx, bx
  68.    jb      p2c_copy
  69.    mov     cx, bx       ; if (CX >= max) CX = max
  70. p2c_copy:
  71.    mov     dx, cx
  72.    les     di, [bp+10]  ; ES:DI = dest
  73.    shr     cx, 1
  74.    rep     movsw
  75.    adc     cx, cx
  76.    rep     movsb
  77.  
  78.    mov     ax, cx
  79.    mov     cx, bx
  80.    sub     cx, dx
  81.    inc     cx
  82.    shr     cx, 1
  83.    rep     stosw        ; Fill unused bytes with NULs
  84.    adc     cx, cx
  85.    rep     stosb
  86.  
  87.    pop    ds
  88.    pop    di
  89.    pop    si
  90.    pop    bp
  91.    ret    10
  92. P2C endp
  93.  
  94. END
  95.